package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.HxXhTransport;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxXhTransportMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxXhTransportParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxXhTransportResult;
import  cn.stylefeng.guns.modular.hx.storage.service.HxXhTransportService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 货物搬运 服务实现类
 * </p>
 *
 * @author ZDW
 * @since 2024-07-25
 */
@Service
public class HxXhTransportServiceImpl extends ServiceImpl<HxXhTransportMapper, HxXhTransport> implements HxXhTransportService {
    @Autowired
    private  HxXhTransportMapper hxXhTransportMapper;
    @Override
    public void add(HxXhTransportParam param){
        HxXhTransport entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxXhTransportParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxXhTransportParam param){
        HxXhTransport oldEntity = getOldEntity(param);
        HxXhTransport newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxXhTransportResult findBySpec(HxXhTransportParam param){
        return null;
    }

    @Override
    public List<HxXhTransportResult> findListBySpec(HxXhTransportParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxXhTransportParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public ResponseData addTask(HxXhTransportParam param) {
    return null;
    }

    @Override
    public List<HxXhTransport> queryAllItem(HxXhTransportParam hxXhTransportParam, String condition) {
        QueryWrapper<HxXhTransport> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", hxXhTransportParam.getState());
        List<HxXhTransport> hxXhTransports = this.baseMapper.selectList(queryWrapper);
        return hxXhTransports;
    }

    @Override
    public HxXhTransportResult findcheckBySpec(HxXhTransportParam hxXhTransportParam1) {
        return this.baseMapper.findcheckBySpec(hxXhTransportParam1);
    }

    @Override
    public HxXhTransportResult findCountGoodsBySpec(HxXhTransportParam hxXhTransportParam) {
        return this.baseMapper.findCountGoodsBySpec(hxXhTransportParam);
    }


    private Serializable getKey(HxXhTransportParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxXhTransport getOldEntity(HxXhTransportParam param) {
        return this.getById(getKey(param));
    }

    private HxXhTransport getEntity(HxXhTransportParam param) {
        HxXhTransport entity = new HxXhTransport();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
